package com.nebula.tlggoods.controller;

import com.nebula.tlggoods.service.GoodsService;
import com.nebula.tlggoods.service.ShopService;
import com.nebula.tlggoods.tools.Record;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 公共控制层
 *
 * @author 星云
 * @date 2019-07-30 11:54
 */
@RestController
public class CommonController {


    @Resource
    private GoodsService goodsService;

    @Resource
    private ShopService shopService;


    /**
     * 统计商品或店铺数量
     *
     * @param keyword   关键字
     * @param countFlag 类型：0店铺，1店铺
     * @return
     */
    @GetMapping("/countGoodsOrShopQuantity")
    @ApiOperation(notes = "统计商品或店铺数量，用于layui分页", value = "统计商品或店铺数量")
    public Record countGoodsQuantity(String keyword, Integer countFlag) {
        Record record = null;
        if (null != countFlag) {
            if (0 == countFlag) {
                record = goodsService.countGoodsQuantity(keyword);
            } else {
                record = shopService.countShopQuantity(keyword);
            }
        }
        return record;
    }
}
